#!/usr/bin/env ruby
# frozen_string_literal: true

# minimize-input: trim each cohort's input to no greater than the longest output's decode length

require "json"

STDERR.puts "[+] pass: minimize-input"

STDIN.each_line do |line|
  result = JSON.parse line, symbolize_names: true

  max_ndecoded = result[:outputs].map { |o| o[:ndecoded] }.max

  # input is hex formatted, so the trimmed length is max_ndecoded * 2
  result[:input] = result[:input][0, max_ndecoded * 2]

  STDOUT.puts result.to_json
end

STDERR.puts "[+] pass: minimize-input done"
